<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="yh.core.funcs.person.data.YHPerson" %>
<%@ page import="yh.core.global.YHConst" %>
<%@ include file="/public/header.jsp"%>
<% 
 String sNoOperate = request.getParameter("noOperate");
 boolean noOperate = false;
 if (!"".equals(sNoOperate) && sNoOperate != null) {
   noOperate = true;
 } 
 String type = "1";
 YHPerson loginUser = (YHPerson)request.getSession().getAttribute(YHConst.LOGIN_USER);
 String flowId = request.getParameter("flowId");  
 String sortId = request.getParameter("sortId");
  String opFlag = request.getParameter("opFlag");
 if (sortId == null) {
   sortId = "";
 }
 if (flowId == null || "".equals(flowId)) {
   flowId = "0";
 }
 String skin = request.getParameter("skin");
 String skinJs = "messages";
 if (skin != null && !"".equals(skin)) {
   skinJs = "messages_" + skin;
 } else {
   skin = "";
 }
 %>
 

<html>
	<head>
		<title>工作办理</title>
	</head>
<script type="text/javascript">
var type = <%=type%>;
var loginUserId = <%=loginUser.getSeqId()%>;
var sortId = "<%=sortId%>";
var flowType = "<%=flowId%>";
var flowId = "<%=flowId%>";
var noOperate = <%=noOperate%>;
var opFlag = <%=opFlag%>;
var skin = "<%=skin %>";
if(type != 3){
    par = "flowId=" + flowId+"&typeStr=" + type + "&sort=";
  }else{
    par = "flowId=" + flowId+"&typeStr=" + type + "&opFlag=" + opFlag + "&sort=";
  }
		$(function(){
			 $("#runId").keypress(function(e) { 
		    	// 回车键事件 
		     	  if(e.which == 13) { 
		     		 doSearch();
		       		} 
		   		}); 
			$('#type_id').combobox({  
        		url:'<%=contextPath %>/yh/core/funcs/workflow/act/YHFlowTypeAct/getFlowTypeJson3_beach.act?sortId=' + sortId,  
       			valueField:'seqId',  
        		textField:'flowName',
        		onChange:function(){
        			doSearch();
        		}
   			});  
			$("#table").datagrid({
				title:"我的工作",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/yh/core/funcs/workflow/act/YHMyWorkAct/getBeachWorkList.act',
				queryParams: {
						flowId:flowId,
						typeStr:type,
						opFlag:opFlag
				},
				nowrap:false,                             
				rownumbers:true,
				fitColumns:true,
				idField:'seqId',
				frozenColumns:[[
				    {field:'ck',checkbox:true},
				    {field:'seqId',hidden:true},
				    {field:'prcsId',hidden:true},
				    {field:'flowId',hidden:true}
				]],
				columns:[[
					{title:'流水号',field:'runId',width:100,align:'center'},
					{title:'流程名称',field:'flowName',width:100,align:'center'},
					{title:'工作文号',field:'runName',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
		
						return "<a onclick=\"formView2("+rowDate.runId+","+rowDate.flowId+","+rowDate.prcsId+","+rowDate.flowPrcs+")\"  href=\"javascript:;\">"+rowDate.runName+"</a>";
						}
					},
					{title:'发起人',field:'userName',width:100,align:'center'},
					{title:'步骤',field:'flowPrcs',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
		
						return "<a onclick=\"flowView("+rowDate.runId+","+rowDate.flowId+",'','','')\"  href=\"javascript:;\">第"+rowDate.flowPrcs+"步:"+rowDate.prcsName+"</a>";
						}
					},
					{title:'操作',field:'read_time',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
		
						return "<a href=\"#\" onclick=\"javascript:opration("+rowDate.runId+","+rowDate.flowId+","+rowDate.prcsId+","+rowDate.flowPrcs+");\">主办</a>&nbsp;&nbsp;"
						}
					},
				]],
				
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb',
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
			
		});
		
		function opration(runId,flowId,prcsId,flowPrcs){
		var myleft=(screen.availWidth-800)/2;
		window.open(contextPath+"/core/funcs/workflow/flowrun/list/inputform/index.jsp?runId="+runId+"&flowId="+flowId+"&prcsId="+prcsId+"&flowPrcs="+flowPrcs+"&sortId=&skin=",runId,"status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=950,height=400,left="+myleft+",top=100");
		}
          
    /**
 * 实际流程图

 * @param runId
 * @param flowId
 * @param title
 * @return
 */
function flowView(runId , flowId , title , sortId , skin) {
  var url = contextPath + "/core/funcs/workflow/flowrun/list/flowview/index.jsp?runId="+runId+"&flowId="+flowId;
  if (sortId) {
    url += "&sortId=" + sortId; 
  }
  if (skin) {
    url += "&skin=" + skin; 
  }
  var myleft=(screen.availWidth-800)/2;
  window.open(url,runId,"status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=950,height=400,left="+myleft+",top=100");
}
/**
 * 打印表单2
 * @param runId
 * @param flowId
 * @return
 */
function formView2(runId , flowId,prcsId,flowPrcs) {
  var url = contextPath + "/core/funcs/workflow/flowrun/list/print/index.jsp?runId="+runId+"&flowId="+flowId+"&prcsId="+prcsId+"&flowPrcs="+flowPrcs;
  window.open(url ,"","status=0,toolbar=no,menubar=no,width="+(screen.availWidth-12)+",height="+(screen.availHeight-38)+",location=no,scrollbars=yes,resizable=yes,left=0,top=0");
}	
		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch(){
			var type_id = $('#type_id').combobox('getValue');
			var runId=$('#runId').val();
			$('#table').datagrid('load',{
				flowId:type_id,
				typeStr:type,
				runId:runId
				});
		}
		
		

	function beachHandler(){
		var rows=jQuery('#table').datagrid('getSelections');
		if(rows.length==0)
		{
			jQuery.messager.alert('提示','请选择需要办理的工作流');  
			return ;
		}
		
		var strs="";
		for(var i=0;i<rows.length;i++){
			if(strs!=""){
				strs+=";";
			}
			strs+=jsonToStr(rows[i]);
		}
		var param = "strs="+encodeURIComponent(strs);
		
		topCenter();
		jQuery.ajax({
			type:'POST',
			url:'<%=contextPath %>/yh/core/funcs/workflow/act/YHWorkTurnAct/beachTurnNext.act',
			data:param,
			success:function(rtJson){
				rtJson = eval('('+rtJson+')');
				if(rtJson.rtState == "0"){
					alert("操作成功！");
					jQuery('#table').datagrid("reload");
				}else{
					alert("操作失败！");
				}
				win.window('close');
			}
		});
		
	}
	var win = null;
	function topCenter(){
		win =  $.messager.show({
            title:'请稍等',
            msg:'正在处理数据...',
            showType:'slide',
            timeout:0,
            modal:false,
            style:{
                right:'',
                top:document.body.scrollTop+document.documentElement.scrollTop,
                bottom:''
            }
        });
    }
	
	/**
	 function progress(){
         var win = $.messager.progress({
             title:'请稍等',
             msg:'正在处理数据...',
             interval:1000
         });
         setTimeout(function(){
             $.messager.progress('close');
         },10000);
     }
		**/
	</script>
	<body style="height:98%">
		<div id="smsManage" class="easyui-layout" data-options="fit:true">
			<div region="center"  style="padding:5px;">
			    	<div id="table" data-options="fit:true"></div>
			    	<div id="tb" style="padding:3px;height:auto">
<div>
   
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="beachHandler();">主办</a>&nbsp;&nbsp;
流程选择：<select id="type_id" name="type_id" style="width:200px;" onchange="doSearch()"></select> 
<div style="display:none;"> 
流水号：<input id="runId" name="runId" style="width:120px" title="流水号"  placeholder="流水号 "/>&nbsp;&nbsp; 
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
						</div>
					</div>
		    </div>
		</div>
	</body>
</html>
